package books4africa

class DonationController {
	
	static navigation = [
		[group:'tabs', action:'list', title:'Donation', order:1],
		]
		
		def springSecurityService
		  def donationService
		  
		  def index() {
				redirect(action: "list", params: params)
		  }
	
		  def list() {
				params.max = Math.min(params.max ? params.int('max') : 10, 100)
				[donationInstanceList: Donation.list(params), donationInstanceTotal: Donation.count()]
		  }
		  
		  
		  def create() {
				[donationInstance: new Donation(params)]
		  }
	
		  def save() {
			  	  
			 def user = springSecurityService.getCurrentUser()
			 user = User.get(user.id)
		
			 def book = Books.get(params.book.id)

			 def donation = donationService.newDonation(book, user, params)
			 
			 flash.message = message(code: 'default.created.message', args: [message(code: 'donation.propertyName.label', default: 'Donation'), donation.id])
			 redirect(action: "list") //, id: donation.id)
		  }
		  
		  def show() {
				def donation = Donation.get(params.id)
				if (!donation) {
					  flash.message = message(code: 'default.not.found.message', args: [message(code: 'donation.propertyName.label', default: 'Donation'), params.id])
					  redirect(action: "list")
					  return
				}
	
				[donationInstance : donation]
		  }
		  
	}
	